global mR pR fR Pm Pp Pf MBSnum PBSnum FBSnum No userNum BSnum PP LM_max LP_max LF_max LL_max PP_w Load_max FBSinfo MBSinfo PBSinfo PP_w_c userinfo
mR=200;
pR=50;
fR=20;
Pm=46; %dbm
Pp=35; %dbm
Pf=20; %dbm

No=-174; %dbm/Hz
MBSnum=1;  
PBSnum=1;
FBSnum=2;
BSnum=MBSnum+PBSnum+FBSnum;
LM_max=40;
LP_max=8;
LF_max=4;
LL_max=ones(1,BSnum);
LL_max(MBSnum)=LM_max;
LL_max(MBSnum+1:MBSnum+PBSnum)=LP_max;
LL_max(MBSnum+PBSnum+1:BSnum)=LF_max;
Load_max=ones(1,BSnum);
Load_max(MBSnum)=80;
Load_max(MBSnum+1:MBSnum+PBSnum)=16;
Load_max(MBSnum+PBSnum+1:BSnum)=8;
PP=ones(1,BSnum);
PP(MBSnum)=Pm;
% PP(MBSnum+1:MBSnum+PBSnum)=round(20+(35-20).*rand(1,PBSnum));
PP(MBSnum+1:MBSnum+PBSnum)=Pp;
% PP(MBSnum+PBSnum+1:BSnum)=round(5+(20-5).*rand(1,FBSnum));
PP(MBSnum+PBSnum+1:BSnum)=Pf;
PP_w=(10.^(PP./10))./1000;
PP_w_c=ones(1,BSnum);
PP_w_c(MBSnum)=712+14.5*PP_w(1);
PP_w_c(MBSnum+1:MBSnum+PBSnum)=13.6+15*PP_w(MBSnum+1:MBSnum+PBSnum);
PP_w_c(MBSnum+PBSnum+1:BSnum)=10.1+15.5*PP_w(MBSnum+PBSnum+1:BSnum);

MBSinfo=setMBS();
Circle_Text(mR,MBSinfo,'r*','r-');
hold on;


PBSinfo=setPBS(PBSnum,MBSinfo);
Circle_Text(pR,PBSinfo,'b*','b-');
hold on;

userNum=100;
FBSinfo=setFBS(FBSnum,MBSinfo,PBSinfo);
Circle_Text(fR,FBSinfo,'g*','g-');
hold on;
St=zeros(100,userNum);
Lat=zeros(100,BSnum);
Lsinr=zeros(100,BSnum);
Ssinr=zeros(100,userNum);


% for userNum=100:20:260
%    Lat=[];
%    St=[];
%    Lsinr=[];
%    Ssinr=[];
%    EEt=[];
%    EEsinr=[];
%    Ct=[];
%    Csinr=[];
%    Ratet=[];
%    Ratesinr=[]; 
for t=1:30

%     [ userinfo ] = setUser_cluster( userNum  );
     userinfo = setUser( userNum );
plot(userinfo(:,1),userinfo(:,2),'b.');

[d, RSRPinfo, SINRinfo, SINRinfo_db]=getRSRP( userNum,userinfo,MBSinfo,PBSinfo,FBSinfo );
[ L_sinr, S_sinr, associationUser_sinr ] = cellA_maxSINR( SINRinfo_db );
[ L_bias, S_bias, associationUser_bias ] = cellA_biasSINR( SINRinfo_db );
[ Degree_initial, Candidate_initial ] = degree_candidate( SINRinfo_db );


%  [ association, La, S,associationUser ] = cell_association( Degree_initial, Candidate_initial, SINRinfo, SINRinfo_db );

[ association1, La1, S1, associationUser1 ] = cell_association_test( Degree_initial, Candidate_initial, SINRinfo, SINRinfo_db )
[ C_sinr, Rate_sinr, EE_sinr ] = perfomance( S_sinr, associationUser_sinr, L_sinr)
[ C_bias, Rate_bias, EE_bias ] = perfomance( S_bias, associationUser_bias, L_bias);
[ C1, Rate1, EE1 ] = perfomance( S1, associationUser1, La1)
Lat(t,:)=La1;
St(t,:)=S1;
Lsinr(t,:)=L_sinr;
Lbias(t,:)=L_bias;
Ssinr(t,:)=S_sinr;
EEt(t,:)=EE1;
EEsinr(t,:)=EE_sinr;
EEbias(t,:)=EE_bias;
Ct(t,:)=C1;
Csinr(t,:)=C_sinr;
Ratet(t,:)=Rate1;
Ratesinr(t,:)=Rate_sinr;
end
eval(['save data',num2str(PBSnum*10)]);



